<?php
/**
 * Created by PhpStorm.
 * User: xin6841414
 * Date: 2018/6/8
 * Time: 12:56
 */

namespace App\Modules\Manage\Http\Controllers;


use App\Http\Controllers\ManageController;
use App\Modules\Manage\Model\ConfigModel;
use App\Modules\Manage\Model\NewsModel;
use App\Modules\Manage\Model\ProductModel;
use App\Modules\Manage\Model\MessageModel;
use Illuminate\Support\Facades\DB;
use Artisan;
use Cache;

class IndexController extends ManageController
{

    public function __construct()
    {
        parent::__construct();
        $this->initTheme('manage');
        $this->theme->setTitle('后台管理');
    }

    public function getManage()
    {
        //访问量
        $data['pvNum'] = DB::select('select pvNum from pv')[0]->pvNum;
        //新闻数量
        $data['newsNum'] = NewsModel::count();
        //产品数量
        $data['productNum'] = ProductModel::count();
        //留言数量
        $data['messageNum'] = MessageModel::count();
        //网站信息
        $data['webInfo'] = ConfigModel::getConfigByType('site');

        return  $this->theme->scope('manage.index',$data)->render();
    }

    public function clearCache()
    {
        Artisan::call('cache:clear');
        Artisan::call('config:clear');
        return redirect()->back()->with(['message'=> '缓存和配置清除成功']);
    }
}